/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package reportcenter.report.dominio.report;

import java.io.File;
import reportcenter.report.dominio.column.ReportColum;
import test.*;
import reportcenter.report.dominio.datasource.DataSource;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.springframework.beans.factory.annotation.Autowired;
import reportcenter.report.dominio.InterfaceFluente;
import reportcenter.report.dominio.report.InterfaceFluenteReport;

/**
 *
 * @author renan_luz
 */
@Entity
@Table(name = "REPORT")
@NamedQueries({@NamedQuery(name = "Report.findByIdR", query = "SELECT r FROM Report r WHERE r.idR = :idR"), @NamedQuery(name = "Report.findByHoraIni", query = "SELECT r FROM Report r WHERE r.horaIni = :horaIni"), @NamedQuery(name = "Report.findByHoraFim", query = "SELECT r FROM Report r WHERE r.horaFim = :horaFim"), @NamedQuery(name = "Report.findByQuery", query = "SELECT r FROM Report r WHERE r.query = :query"), @NamedQuery(name = "Report.findByTitle", query = "SELECT r FROM Report r WHERE r.title = :title"), @NamedQuery(name = "Report.findBySubtitle", query = "SELECT r FROM Report r WHERE r.subtitle = :subtitle"), 
               @NamedQuery(name = "Report.findAll", query= "SELECT r FROM Report r")})
public class Report implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name = "ID_R", nullable = false)
    private Integer idR;
    @Column(name = "HORA_INI", nullable = false)
    @Temporal(TemporalType.TIME)
    private Date horaIni;
    @Column(name = "HORA_FIM", nullable = false)
    @Temporal(TemporalType.TIME)
    private Date horaFim;
    @Column(name = "QUERY", nullable = false)
    private String query;
    @Column(name = "TITLE", nullable = false)
    private String title;
    @Column(name = "SUBTITLE", nullable = false)
    private String subtitle;
    @JoinColumn(name = "ID_D", referencedColumnName = "ID_D")
    @ManyToOne
    private DataSource idD;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idR")
    private Collection<ReportColum> reportColumCollection;
    
    
    
    public Report() {
    }
    
    public static InterfaceFluenteReport criarCom() {
        return InterfaceFluente.create(
                new Report(), InterfaceFluenteReport.class);
    }

    public Report(Integer idR) {
        this.idR = idR;
    }

    public Report(Integer idR, Date horaIni, Date horaFim, String query, String title, String subtitle) {
        this.idR = idR;
        this.horaIni = horaIni;
        this.horaFim = horaFim;
        this.query = query;
        this.title = title;
        this.subtitle = subtitle;
    }

    public Integer getIdR() {
        return idR;
    }

    public void setIdR(Integer idR) {
        this.idR = idR;
    }

    public Date getHoraIni() {
        return horaIni;
    }

    public void setHoraIni(Date horaIni) {
        this.horaIni = horaIni;
    }

    public Date getHoraFim() {
        return horaFim;
    }

    public void setHoraFim(Date horaFim) {
        this.horaFim = horaFim;
    }

    public String getQuery() {
        return query;
    }

    public void setQuery(String query) {
        this.query = query;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getSubtitle() {
        return subtitle;
    }

    public void setSubtitle(String subtitle) {
        this.subtitle = subtitle;
    }

    public DataSource getIdD() {
        return idD;
    }

    public void setIdD(DataSource idD) {
        this.idD = idD;
    }

    public void addReportColumn(ReportColum column) {
        if(getReportColumCollection() == null){
            reportColumCollection = new ArrayList<ReportColum>();
        }
        getReportColumCollection().add(column);
        column.setIdR(this);
    }

    public Collection<ReportColum> getReportColumCollection() {
        return reportColumCollection;
    }

    public void setReportColumCollection(Collection<ReportColum> reportColumCollection) {
        this.reportColumCollection = reportColumCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idR != null ? idR.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Report)) {
            return false;
        }
        Report other = (Report) object;
        if ((this.idR == null && other.idR != null) || (this.idR != null && !this.idR.equals(other.idR))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "test.Report[idR=" + idR + "]";
    }
}
